#include "stdafx.h"
#include "XDlg.h"
#include "HttpClient.h"

XDlg::XDlg(LPCTSTR pszXmlName): SOUI::SHostDialog(pszXmlName) {
    m_MsgLoop->AddMessageFilter(this);
}

XDlg::~XDlg() {

}

BOOL XDlg::PreTranslateMessage(MSG *pMsg) {

    if (pMsg->message == WM_HTTP_DATA) {
        xHttpClient.Process();
    }
    return FALSE;
}

void XDlg::OnFinalMessage(HWND hWnd) {

    if (m_MsgLoop) {
        m_MsgLoop->RemoveMessageFilter(this);
    }
    
    SOUI::SHostDialog::OnFinalMessage(hWnd);
}

void XDlg::setCtrlText(const SOUI::SStringW &ctrlName, const SOUI::SStringW &text,
                       const SOUI::SStringW &textColor, const SOUI::SStringW &ctrlSkin) {
    auto ctrl = FindChildByName(ctrlName);
    if (ctrl) {
        ctrl->SetWindowText(text);
        if (!textColor.IsEmpty()) {
            ctrl->SetAttribute(L"colorText", textColor);
        }
        if (!ctrlSkin.IsEmpty()) {
            ctrl->SetAttribute(L"skin", ctrlSkin);
        }
    }
}

